function rslice_velocity_overlay_redraw ( hObject )
% RSLICE_VELOCITY_OVERLAY_REDRAW:

rslice_handles = guihandles ( hObject );
rslice_data = guidata ( hObject );

hvo_handles = guihandles ( rslice_data.hvoc_figure );
hvo_data = guidata ( rslice_data.hvoc_figure );


%
% Make the window visible
set ( hvo_handles.figure1, 'Visible', 'On' );
figure ( hvo_handles.figure1 );

%
% If the handle for the arrows already exists, then get rid of it.
if isfield ( rslice_data, 'psliceuv_arrows' )
	try
		delete ( rslice_data.psliceuv_arrows );
	end
end


%
% Is the toggle button toggled?  If not, then do nothing
show_or_hide_arrows = get ( hvo_handles.show_hide_arrows_toggle, 'Value' );
if ( show_or_hide_arrows == 0 )
	return
end


%
% Get the RGB triplet.
red = get ( hvo_handles.hvo_red_slider, 'Value' );
green = get ( hvo_handles.hvo_green_slider, 'Value' );
blue = get ( hvo_handles.hvo_blue_slider, 'Value' );
arrow_color = [red green blue];


%
% Get the scale.
arrow_scale = get ( hvo_handles.hvo_scale_slider, 'Value' );


%
% Get the sample rate.
sampling_rate = get ( hvo_handles.hvo_subsample_slider, 'Value' );
sampling_rate = round ( sampling_rate );


% 
% what is the file index?
file_time_index = rslice_data.timestep - rslice_data.ncfile_start_index(rslice_data.ncfile_index);

%
% And finally, draw the arrows!
ncfile = rslice_data.ncfile_list { rslice_data.ncfile_index };
axes ( rslice_handles.horizontal_slice_axis );

hold on
	
%
% Get the data
%
% If the data variable has no depth dimension, then retrieve the uv
% data as averaged.  That's ubar and vbar.
if ( strcmp ( rslice_data.dim_type, 'TYX' ) | strcmp ( rslice_data.dim_type, 'YX' ) )

	[velocity,xv,yv] = roms_depaveuv ( rslice_data, rslice_data.timestep );

%
% Ok, so the data DOES have a depth dimension.  Are we supposed to slice
% along a sigma coordinate?
elseif rslice_data.hslice_on_sigma

	[velocity,xv,yv] = roms_ksliceuv ( rslice_data, file_time_index, rslice_data.sigma_index );

%
% Or do we slice along a constant depth?
elseif isfield ( rslice_data, 'depth' )

	[velocity,xv,yv] = roms_zsliceuv ( rslice_data, file_time_index, -1 * rslice_data.depth );

%
% Or a weird error has arisen.
else

	msg = sprintf ( 'Unsure how we are supposed to display the velocity information.' );
	rslice_error ( msg );
		    
		    
end
	            

	            
	
%
% Need to keep the current axis limits.
xlim = get ( gca, 'xlim' );
ylim = get ( gca, 'ylim' );
rslice_data.psliceuv_arrows = psliceuv ( xv, yv, velocity, sampling_rate, arrow_scale, arrow_color );
	
set ( gca, 'xlim', xlim, 'ylim', ylim );

%
% Save the arrows handles so we can retrieve it later.
guidata ( hObject, rslice_data );

return
